const Koa = require('koa')
const Router = require('koa-router')
const serve = require('koa-static')
const Pug = require('pug')
// const pugTpl = require('./tpl').pugTpl
// const { getCourses } = require('./service/courses')

const app = new Koa()
const router = new Router()

// router.get('/courses/:courseid/chepter/:chepterid', async (ctx, next) => {
//   const { courseid, chepterid } = ctx.params
//   let course = await getCourses(courseid, chepterid)
//   ctx.body = Pug.render(pugTpl, {
//     courseid,
//     chepterid,
//     pages: course.pages,
//     nav: course.nav,
//     body: course.body
//   })
// })

router.all('/*', async(ctx, next) => {
  // ctx.response.status = 404;
  ctx.response.body ='<div>很抱歉，您要访问的页面不存在！</div>'
  // ctx.redirect('/courses/vim/chepter/1')
  
})

app
  // .use(serve(__dirname + '/public'))
  .use(router.routes())
  .use(router.allowedMethods())
  .listen(8080)
console.log('localhost:8080')